#include<bits/stdc++.h>
using namespace std;
const int maxn=3000005,mod=998244353;
int n;
int f[maxn][2],g[maxn],ok[maxn],lst[2][2],nxt[maxn][2];
string s;
int main(){
	freopen("song.in","r",stdin);
	freopen("song.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>s,n=s.size(),s=" "+s,lst[0][0]=lst[0][1]=lst[1][0]=lst[1][1]=n+1;
	for(int i=n;i>=1;i--)
		lst[i&1][s[i]-65]=i,nxt[i][0]=lst[i&1][0],nxt[i][1]=lst[i&1][1];
	ok[n+1]=g[n+1]=1;
	for(int i=n;i>=1;i--){
		f[i][0]=g[nxt[i][0]+1];
		if(s[i]=='A')
			ok[i]=ok[nxt[i+1][0]+1],f[i][1]=f[nxt[i+1][0]+1][1];
		else ok[i]=(n-i)&1,f[i][1]=(((n-i)%2==0)+f[nxt[i+1][0]][0]+f[nxt[i+1][1]][1])%mod;
		g[i]=(ok[i]+f[i][0]+f[i][1])%mod;
	}
	printf("%d\n",g[1]);
	return 0;
}

